package pl.oczadly.jabberclient.mainwindow.model;

import java.util.Iterator;
import java.util.Vector;

public class MyListModel {

	private static MyListModel instance;
	
	private Vector<Account> contacts;
	
	private MyListModel() {
		contacts = new Vector<Account>();
	}
	
	public static MyListModel getInstance() {
		if( instance == null )
			instance = new MyListModel();
		
		return instance;
	}
	
	public void add( String id, String name ) {
		contacts.add( new Account( id, name ) );
	}
	
	public void remove( String id, String name ) {
		for( Iterator<Account> it = contacts.iterator(); it.hasNext(); ) {
			Account account = it.next();
			if( ( account.getId() == id ) && ( account.getName() == name ) )
				contacts.remove( account );
		}
	}
	
	public void removeAll() {
		contacts.removeAll( contacts );
	}
	
	public Account getAccount( String id, String name ) {
		for( Iterator<Account> it = contacts.iterator(); it.hasNext(); ) {
			Account account = it.next();
			if( ( account.getId() == id ) && ( account.getName() == name ) )
				return account;
		}
		return null;
	}
	
	public Vector<Account> getAll() {
		return contacts;
	}
}
